
<!--
All rights Reserved, Designed By www.youyacao.com
@Description:用户提现列表
@author:成都市一颗优雅草科技有限公司
@version V4.2
注意：本前端源码遵循 MIT开源协议本内容仅限于个人参考，禁止用于其他的商业用途
需要商业用途或者定制开发等可访问songshu.youyacao.com   联系QQ:422108995 23625059584
开源gitee地址：https://gitee.com/youyacao/songshu-video-page
 -->


<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-cascades"></i> 用户提现
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-input v-model="query.name" placeholder="用户名/用户ID/手机号" class="handle-input mr10"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
      </div>
      <el-table
        :data="tableData"
        border
        class="table"
        ref="multipleTable"
        header-cell-class-name="table-header"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column prop="id" label="ID" width="55" align="center"></el-table-column>
        <el-table-column prop="uname" label="用户">
          <template slot-scope="scope">
            <div v-if="scope.row.uname">{{scope.row.uname}}</div>
            <div v-else style="color: #8c939d;">已删除</div>
          </template>
        </el-table-column>
        <el-table-column label="提现金币" prop="num" align="center">
        </el-table-column>
        <el-table-column label="提现金额(元)" prop="money" align="center">
        </el-table-column>
        <el-table-column prop="before_money" label="收款信息">
          <template slot-scope="scope">
            <div>{{scope.row.bank}}：{{scope.row.account}}({{scope.row.name}})</div>
            <div>开户银行：{{scope.row.bankname}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="提交时间"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 1">
              <div style="color: #67c23a;">已完成</div>
              <div>时间:{{scope.row.updated_at}}</div>
            </div>
            <div v-else-if="scope.row.status == 2">
              <div style="color: #e6001a;">拒绝</div>
              <div>原因：{{scope.row.remark}}</div>
              <div>时间:{{scope.row.updated_at}}</div>
            </div>
            <div v-else>
              <el-button
                type="text"
                icon="el-icon-s-check"
                @click="handlePass(scope.$index, scope.row)"
              >完成
              </el-button>
              <el-button
                type="text"
                icon="el-icon-error"
                class="red"
                @click="handleRefuse(scope.$index, scope.row)"
              >拒绝
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          layout="total, prev, pager, next"
          :current-page="query.page"
          :page-size="query.pageSize"
          :total="total"
          @current-change="handlePageChange"
        ></el-pagination>
      </div>
    </div>

    <!-- 编辑弹出框 -->
    <el-dialog title="拒绝提现" :visible.sync="editVisible" width="30%">
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="拒绝原因">
          <el-input v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveEdit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'basetable',
    data() {
      return {
        query: {
          name: '',
          page: 1,
          pageSize: 10
        },
        tableData:[],
        total: 0,
        form: {},
        editVisible:false
      }
    },
    created() {
      this.getData()
    },
    methods: {

      // 获取 easy-mock 的模拟数据
      getData() {
        this.$api.user.withdrawlist(this.query).then(res => {
          this.tableData = res.data
          this.total = res.total || 0
        })
      },
      // 触发搜索按钮
      handleSearch() {
        this.$set(this.query, 'page', 1)
        this.getData()
      },
      handlePass(index,item){
        this.$confirm('确认完成此提现申请？').then(_ => {
            this.$api.user.withdraw({id:item.id,type:1}).then((res)=>{
              if (res.code == 1) {
                this.$message.error(res.msg)
                return
              }
              this.$message.success(res.msg)
              this.getData()
            });
          })
          .catch(_ => {});
      },
      handleRefuse(index,item){
        this.editVisible = true;
        this.form = {id:item.id,type:2,remark:'不可提现'};
      },
      saveEdit(){
        this.$api.user.withdraw(this.form).then((res)=>{
          if (res.code == 1) {
            this.$message.error(res.msg)
            return
          }
          this.editVisible = false;
          this.$message.success(res.msg)
          this.getData()
        });
      },
      // 分页导航
      handlePageChange(val) {
        this.$set(this.query, 'page', val)
        this.getData()
      },
      // 多选操作
      handleSelectionChange(val) {
        this.multipleSelection = val
      }
    }
  }
</script>

<style scoped>
  .pointer {
    cursor: pointer;
  }

  .handle-box {
    margin-bottom: 20px;
  }

  .handle-select {
    width: 120px;
  }

  .handle-input {
    width: 300px;
    display: inline-block;
  }

  .table {
    width: 100%;
    font-size: 14px;
  }

  .red {
    color: #ff0000;
  }

  .mr10 {
    margin-right: 10px;
  }

  .table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
  }

  .type-icon {
    display: block;
    width: 150px;
    height: 150px;
  }
</style>
